<!-- 历史转塘记录 -->
<template>
  <BaseMainSlot :show-tab="false" :showBtnBox="false">
    <template v-slot:search-box>
      <el-collapse v-model="activeName" accordion @change="handleChange">
        <el-collapse-item name="1">
          <template slot="title">
            <div class="select-btns search-btns" @click.stop="changeSelect()">
              <i class="el-icon-circle-check"></i>
              <p v-if="activeName === '1'">收起筛选</p>
              <p v-if="activeName === ''">展开筛选</p>
            </div>
          </template>
          <div class="search-btn search-btns" @click.stop="queryPageList(),searchPage()">
            <i class="el-icon-circle-check"></i>
            <p>查询</p>
          </div>
          <div class="select-box-content">
            <div class="select-box-content-name">原先批次</div>
            <el-select filterable clearable v-model="sourceProductionBatchId" filterable clearable>
              <el-option v-for="(item, index) in batchList" :key="index"
                :label="`${item.mnecode}_${item.varietyName}`" :value="item.productionBatchId" />
            </el-select>
          </div>
          <div class="select-box-content">
            <div class="select-box-content-name">转后批次</div>
            <el-select filterable clearable v-model="targetProductionBatchId" filterable clearable>
              <el-option v-for="(item, index) in batchList" :key="index"
                :label="`${item.mnecode}_${item.varietyName}`" :value="item.productionBatchId" />
            </el-select>
          </div>
          <div class="select-box-content">
            <div class="select-box-content-name">转塘操作人</div>
            <el-select filterable clearable v-model="staffName" filterable clearable>
              <el-option v-for="(item, index) in staffList" :key="index" :label="item.staffName"
                :value="item.staffName" />
            </el-select>
          </div>
          <div class="select-box-content">
            <div class="select-box-content-name">转塘日期</div>
            <el-date-picker v-model="recordDate" type="date" placeholder="选择日期" value-format="yyyy-MM-dd" clearable />
          </div>
        </el-collapse-item>
      </el-collapse>
    </template>
    <template v-slot:tab-select></template>
    <template v-slot:table-box>
      <el-table ref="tableData" v-loading="loading" highlight-current-row :data="tableData" class="margin-top10px" stripe
        border height="calc(100% - 50px)" :row-key="row => {
          return row.transferSeparatePondId;
        }
          ">
        <!-- <el-table-column type="selection" width="55" :reserve-selection="true" :selectable="(row) => { return !row.selectable }" /> -->
        <el-table-column type="index" label="序号" width="50">
          <template slot-scope="scoped">
            {{ scoped.row.transferSeparatePondId ? scoped.$index + 1 : '' }}
          </template>
        </el-table-column>
        <el-table-column prop="sourceMnecode" label="原先批次" />
        <el-table-column prop="targetMnecode" label="转后批次" />
        <el-table-column prop="staffName" label="转塘操作人" />
        <el-table-column prop="recordDate" label="转塘日期" />
        <el-table-column width="120" label="转入信息">
          <template v-if="scope.row.transferSeparatePondId" slot-scope="scope">
            <el-button class="text-btn-cursor" type="text" size="small" @click="showDetail(scope.row)">点击查看
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <Pagination :page-size="pageSize" :current-page="currentPage" :total-size="totalSize"
        @changeCurrentPage="changeCurrentPage" />
      <CompleteInfoDialog ref="completeInfoDialog" :now-chance-stau="nowChanceStau"
        :complete-info-object="completeInfoObject" :show.sync="showCompleteInfoDialog" @closeDialog="closeDialog"
        @cancelDialog="cancel" />
    </template>
  </BaseMainSlot>
</template>

<script>
// import ActionBar from "@/components/ActionBar";
import Pagination from "@/components/Pagination";
import BaseMainSlot from "@/components/BaseMainSlot/newBaseMainSlot.vue";
// import AddEditDialog from "./components/add-edit-dialog.vue";
import CompleteInfoDialog from "./components/complete-info-dialog.vue";
import { mymixin } from "@/utils/mixin";
import { mapGetters } from 'vuex';

import BatchMangeApi from "@/api/batch-mange"
import TransferSeparatePondApi from "@/api/batch-mange/transfer-separate-pond"
import FishVarietyApi from "@/api/basic-info-manage/fishVariety"
import StaffApi from "@/api/basic-info-manage/staff";
export default {
  name: 'HistoryInputPondRecord',
  components: { Pagination, BaseMainSlot, CompleteInfoDialog },
  mixins: [mymixin],
  data () {
    return {
      mnecode: "",//批次编号
      sourceProductionBatchId: "",//原先批次
      targetProductionBatchId: "",//转后批次
      fishVarietyId: "",//养殖品种ID
      staffName: '',//转塘操作人
      recordDate: "",//转塘日期
      checkedIdList: [],
      batchList: [],//
      FishVarietyData: [],//全部品种
      staffList: [],//全部员工/转塘人
      showAddEditDialog: false,
      activeName: '1',//控制是否默认展开
      completeInfoObject: {},
      showCompleteInfoDialog: false
    };
  },
  computed: {
    ...mapGetters({
      judgePermission: "permission/judgePermission"
    })
  },
  watch: {},
  created () {
    this.queryPageList();
  },
  mounted () {
    this.queryFishVariety()
    this.queryStaff()
    this.queryBatch()
  },
  methods: {
    searchPage(){
      this.currentPage=1
      this.queryPageList();
      setTimeout(() => {
        this.queryPageList();
      }, 200);
    },
    queryPageList () {
      let params = {
        page: this.currentPage,
        size: this.pageSize,
        entity: {}
      };
      if (this.sourceProductionBatchId) params.entity.sourceProductionBatchId = this.sourceProductionBatchId;
      if (this.targetProductionBatchId) params.entity.targetProductionBatchId = this.targetProductionBatchId;
      if (this.fishVarietyId) params.entity.fishVarietyId = this.fishVarietyId;
      if (this.staffName) params.entity.staffName = this.staffName;
      if (this.recordDate) params.entity.recordDate = this.recordDate;
      TransferSeparatePondApi.queryPageByCondition(params).then(res => {
        if (res.success === true) {
          let data = res.data || {};
          this.totalSize = data.totalElements;
          // 赋值数组
          this.tableData = data.content;
          this.addblankmet();
          this.resetActionBar();
        }
      });
    },
    //查询可选鱼类品种
    queryFishVariety () {
      FishVarietyApi.queryByCondition().then(res => {
        this.FishVarietyData = res.data;
      })
    },
    //查询批次
    queryBatch () {
      BatchMangeApi.queryByCondition().then(res => {
        this.batchList = res.data;
      })
    },
    //查询转塘人
    queryStaff () {
      StaffApi.queryByCondition().then(res => {
        this.staffList = res.data;
      })
    },
    changeCurrentPage (currentPage) {
      this.currentPage = currentPage;
      this.queryPageList();
    },
    selectAll (list) {
      let notvalue = true
      list.forEach(item => {
        if (!item.transferSeparatePondId) {
          notvalue = false
        }
      });
      if (notvalue === false) {
        this.$message.warning("不可选择空数据！");
      }
    },
    select (list) {
      let notvalue = true
      list.forEach(item => {
        if (!item.transferSeparatePondId) {
          notvalue = false
        }
      });
      if (notvalue === false) {
        this.$message.warning("不可选择空数据！");
      }
    },
    handleSelectionChange (list) {
      this.checkedIdList = [];
      let notvalue = true
      let emptyList = []
      this.checkedIdList = list.map(item => {
        if (item.transferSeparatePondId) {
          return item.transferSeparatePondId
        } else {
          notvalue = false
          emptyList.push(item)
          return ""
        }
      });
      if (notvalue === false) {
        // this.$message.warning("不可选择空数据！");
        this.toggleNoSelection(emptyList)
        return
      }
      if (this.checkedIdList.length >= 1) this.delActive = true;
      else this.delActive = false;
    },
    showDetail (row) {
      if (row.transferSeparatePondId) {
        this.completeInfoObject = JSON.parse(JSON.stringify(row));
        this.showCompleteInfoDialog = true
      }
    },
    // 单个删除
    delOne (row) {
      this.$confirm("此操作将永久删除该项, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        
      })
        .then(() => {
          TransferSeparatePondApi.delById({ id: row.transferSeparatePondId }).then(res => {
            if (res.success === true) {
              this.$message.success("删除成功!");
              this.queryPageList();
              this.resetActionBar();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    // 添加
    add () {
      this.nowChanceStau = 'add'
      this.titleText = "添加"
      this.addActive = false;
      this.delActive = false;
      this.showAddEditDialog = true
    },
    // 修改
    edit (row) {
      if (row.transferSeparatePondId) {
        this.editObject = JSON.parse(JSON.stringify(row));
        this.nowChanceStau = 'edit'
        this.titleText = "修改"
        this.addActive = false;
        this.delActive = false;
        this.showAddEditDialog = true
      } else {
        this.editObject = {}
      }
    },
    // 取消
    cancel () {
      this.nowChanceStau = '';
      this.titleText = ''
      this.editObject = {}
      this.addActive = true;
      this.delActive = false;
      this.showAddEditDialog = false
      this.showCompleteInfoDialog = false;
    },
  }
};
</script>

<style lang="scss" scoped></style>
